/* Copyright (C) 2013-2021 TU Dortmund
 * This file is part of LearnLib, http://www.learnlib.de/.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package de.learnlib.examples;

import net.automatalib.automata.transducers.impl.compact.CompactMealy;
import net.automatalib.util.automata.random.RandomAutomata;
import net.automatalib.words.impl.Alphabets;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.*;

/**
 * This example constructs random mealy
 *
 * @author z11panyan
 */
@SuppressWarnings("PMD.SystemPrintln")
public final class RandomMealyConstruct {

    private static final int EXPLORATION_DEPTH = 4;

    private RandomMealyConstruct() {
        // prevent instantiation
    }

    public static void main(String[] args) throws IOException {

        // load Mealy and alphabet
        int sizeInput = 10;
        int sizeOutput = 10;

        for(int size = 100; size < 201; size = size + 100)
        {
            for(int i = 0; i < 100; i++)
            {
                CompactMealy<Integer,Integer> target = constructSUL(sizeInput,sizeOutput,size);
                recordSUL(target,size,i);
            }
        }


    }

    /**
     * creates random mealy
     *
     * @return a mealy
     */
    private static CompactMealy<Integer,Integer> constructSUL(int numInputs,int numOutputs, int size) {
        CompactMealy<Integer,Integer> randomMealy = RandomAutomata.randomMealy(new Random(), size, Alphabets.integers(0, numInputs - 1), Alphabets.integers(0, numOutputs - 1));
        return randomMealy;
    }

    private static void recordSUL( CompactMealy<Integer,Integer> randomMealy, int size,int index) {
        try {
            PrintWriter out = new PrintWriter("/home/model/Mealy"+size+"-"+randomMealy.getInputAlphabet().size()+"-10_"+index+".mealy");//输出的路径和文件名

            out.printf("%d %d %n", randomMealy.size(), randomMealy.getInputAlphabet().size());

            for (int i = 0; i < randomMealy.size(); i++) {
                for (int j = 0; j < randomMealy.getInputAlphabet().size(); j++)
                {
                    out.printf("%d ", randomMealy.getSuccessor(i, j));
                }
                out.printf("%n");
            }

            for (int i = 0; i < randomMealy.size(); i++) {
                for (int j = 0; j < randomMealy.getInputAlphabet().size(); j++)
                {
                    out.printf("%d ", randomMealy.getOutput(i,j)) ;
                }
                out.printf("%n");
            }
            out.close();
        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        }
    }

}
